package com.zmx.gateway.config.currentlimit;

import com.zmx.gateway.utils.IpAdressUtil;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

/**
 * @Description: 限流策略-ip
 * @ClassName: IpKeyResolverConfig
 * @Author zhaomxr
 * @Date 2022-01-19 09:41
 */
@Configuration
public class IpKeyResolverConfig {

    @Bean("ipKeyResolver")
    KeyResolver ipKeyResolver() {
        return exchange -> Mono.just(IpAdressUtil.getIpAddress(exchange.getRequest()));
    }
}
